
#
# 'make depend'			uses makedepend to automatically generate dependencies 
#							(dependencies are added to end of Makefile)
# 'make'				build executable file (need first to build gtest)
# 'make clang'			build executable file (need first to build gtest) witg
#							clang++ as compiler
# 'make debug'			build executable file (need first to build gtest) with
#							debug symbols
# 'make run'			build executable file (need first to build gtest) with
#							optimalization
# 'make gtest'			build gtest lib
# 'make gtest_debug'	build gtest lib with debug symbols
# 'make gtest_release'	build gtest lib with optimalization
# 'make clean'			removes all .o and temporary files
# 'make cleanall'		removes all .o, temporary files, gtest lib and 
#							executable file
#
# 'make all'			it's same to sequentially do:
#							'make cleanall'
#							'make gtest'
#							'make'
# 'make all_debug'		it's same to sequentially do:
#							'make cleanall'
#							'make gtest_debug'
#							'make debug'
# 'make all_release'	it's same to sequentially do:
#							'make cleanall'
#							'make gtest_release'
#							'make release'
#
# 'make run'			runs last builded executable file
#

CXX						= g++
CXXFLAGS				= -Wall -pedantic -std=c++11

INCLUDES				= -I../include/ -I${GTEST_DIR}/include -I./
 
LFLAGS					=
LIBS					= -lpthread

SRCS					= src/core/boolean_test.cpp		\
						  src/core/float_test.cpp		\
						  src/core/if_test.cpp			\
						  src/core/types_test.cpp		\
						  src/algorithm_test.cpp		\
						  src/ext_test.cpp				\
						  src/functional_test.cpp		\
						  src/initializer_list_test.cpp	\
						  src/iterator_test.cpp			\
						  src/list_test.cpp
OBJS					= $(SRCS:.cpp=.o) 

MAIN					= gtest_main
MAINEXT					= cc
MAINDIR					= libs/gtest/src
MAINSRC					= $(MAINDIR)/$(MAIN).$(MAINEXT)
MAINOBJ					= $(MAINSRC:.$(MAINEXT)=.o)

GTEST					= gtest
GTEST_DIR				= libs/gtest

ODIR					= obj

entry:					$(GTEST) $(MAIN) $(OBJS)
						$(CXX) $(CXXFLAGS) $(INCLUDES) -o $(MAIN) \
							$(MAIN).o libgtest.a $(OBJS) $(LFLAGS) $(LIBS)

clang:					CXX = clang++
clang:					entry

debug:					CXXFLAGS += -g
debug:					entry

release:				CXXFLAGS += -O3
release:				entry

$(GTEST):				${GTEST_DIR}/src/gtest-all.cc 
						$(CXX) $(CXXFLAGS) -I${GTEST_DIR}/include \
							-I${GTEST_DIR} -c ${GTEST_DIR}/src/gtest-all.cc
						ar -rv libgtest.a gtest-all.o

$(GTEST)_debug:			CXXFLAGS += -g
$(GTEST)_debug:			$(GTEST)

$(GTEST)_release:		CXXFLAGS += -O3
$(GTEST)_release:		$(GTEST)

all:					cleanall
all:					entry

all_debug:				CXXFLAGS += -g
all_debug:				all

all_release:			CXXFLAGS += -O3
all_release:			all

run:
						./$(MAIN)

$(MAIN):				$(MAINSRC)
						$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $(MAIN).o

%.o:					%.cpp
						$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

.PHONY:					depend clean
clean:
						$(RM) ${OBJS} *~ $(MAIN).o gtest-all.o

cleanall:				clean
						$(RM) $(MAIN) libgtest.a

depend:					$(SRCS)
						makedepend $(INCLUDES) $^

# DO NOT DELETE THIS LINE -- make depend needs it

